Loading...
 

CX_ASCII_FILE - ASCII file

CX_ASCII_FILE  CX_ASCII_FILE.png Iterable

Class hierarchy
Description:

An object of this class refers to an ASCII file, provides methods for reading and writing as well as for simple file operations. (The class CX_FILE_INFO is available for the management of files themselves).

File encoding

The class supports several common file encodings (not only ASCII).

When reading files with known encoding, the encoding should always be set Read explicitly before opening the file. If the encoding is not known, DetectCodepage should be used to determine the code page (if possible) from the file contents.

When writing files, the encoding defined by the receiving file interface should always be explicitly set. If nothing has been defined, the UTF-8 encoding should be used, which can represent all characters efficiently and is supported by most modern programmes.

Attention: The default encoding has been changed from CP850 to UTF-8 as of Dll version 228586.

Note: The TransTable command can be used to register byte translation tables for reading via Read . These are applied to the read data BEFORE the conversion from the set file encoding to the encoding of the ClassiX system (UTF-8) is carried out. This means that any code pages can be supported - even ASCII-incompatible ones such as EBCDIC!

Record formats

Variable sentences as well as sentences with fixed length and fixed data positions are supported:

Format Record length (when reading) Data fields
fixed a) set a fixed value
b) specify value 0 - end marker \r or \n defines record length - SetRecordFormat
a) Specify length (fields follow immediately after each other)
b) Define position and length - SetRecordFormat
variable End of record indicator - SetRecordSeparator Separator - SetFieldSeparator

Default setting for reading: is variable record length, the end of record determines NL, CR or a combination of both.
While using a file, the record format can be changed, so that, for example, data can be written first in variable form and then in a fixed record structure. Therefore, this class can handle both typesetting formats simultaneously.

Application examples:

  1. Import/export of data
  2. Datanorm interface

CSV import:

Since the import of data in CSV format occurs particularly often, the options that should be considered when importing CSV data are listed here.

  1. SetFieldSeparator should normally be set to "," for CSV, but Microsoft Excel exports the fields with ";" as separator. In case of doubt, you have to look into the file here.
  2. According to RFC 4180, fields may contain separators and line breaks if the values are enclosed in inverted commas. This behavior is disabled by default for CX_ASCII_FILE and must be enabled by calling ContainsStrings . Please note that the inverted commas must then be strictly paired. Some CSV exports do not attach any special meaning to inverted commas, in which case ContainsStrings must not be used.
  3. If ContainsStrings is used, there are two options for how inverted commas should be displayed in a field. ClassiX uses the sequence \" by default and RFC 4180 specifies "" for this. If inverted commas occur within fields, the file should be examined to determine which style is used. To use the RFC conform style, the method EscapeQuotesRFCConform must be called.
  4. CSV files can also contain special characters, umlauts & co. in fields. To ensure that these are read in correctly, DetectCodepage and SetCodepage should be used or the file should be opened in an editor such as Notepad++ so that it can determine the character encoding of the file and this must be set via one of the following calls.

Code example:

Var(inputFile)
CreateTransObject(CX_ASCII_FILE) -> inputFile
"CX_ROOTDIR\\test.txt" inputFile Put(fileName)

do {
  LocalVar(record)
  inputFile Call(Read) Revert -> record
  inputFile Call(Eof) if break
  // record hier verarbeiten
} loop
inputFile Call(Close)    // Datei schließen

181614 CX_ASCII_FILE can be iterated and the above example can be simplified as follows

Code example:
Var(inputFile)
CreateTransObject(CX_ASCII_FILE) -> inputFile
"CX_ROOTDIR\\test.txt" inputFile Put(fileName)

inputFile iterate {
  LocalVar(record)
  Revert -> record
  // record hier verarbeiten
}

inputFile Call(Close)  //Datei schließen
List of methods (MDI)
Function MA* Parameters Return Brief description
AcceptInvalidPackedDataFields no error message for incorrectly packed data fields
ANSICode Setting the ANSI character set
Append Append output to file
BuildIndexFile (INTEGER, INTEGER) Structure of an index file
CheckIndex (INTEGER) VECTOR Statistics on the effectiveness of the hash algorithm.
Close Closing a file
ContainsStrings special handling of quoted strings when reading in variable sentence format (no significance for fixed sentence format and write operations)
CopyFile (STRING, INTEGER) Copies a file to another location
CP850Code Setting the ISO/CP850 character set
Create Create file
Delete Deletes the file and its index file
DetectCodepage
228519
STRINGAttempts to determine the character set of the file from the file contents.
Eof INTEGER Tests the file end
EscapeQuotesRFCConform Enables RFC 4180 compliant string handling for CSV files
Exists (STRING) INTEGER Check whether a specific file exists
FileExchange Switches the file
FileLength INTEGER File size in bytes
FilePos INTEGER Position of the file pointer
GetDirInfo (STRING) CX_FILE_INFO Return directory information
GetFieldFromBuffer (INTEGER) STRING Return of a specific field of the buffer area
GetFileInfo CX_FILE_INFO Returning file information
IsOpen INTEGER Check that the file is open
MoveFile (STRING) Moves a file from a directory to the specified directory.
Open Opening a file
PackedDataFields VECTOR. determine data fields packed in IBM format
Read VECTOR Read the next sentence
ReadIntoBuffer Reading the next record into the buffer area
ReadVariableFieldsReplaceHexNull (STRING) VECTOR Reading the next block, replacing all zero bytes with the parameter.
Ready
Up to Dll version 228508
Synchronisation for parallel access to the same CX_ASCII_File object
ReformatRecord (VECTOR, INTEGER) Changing a fixed record format
ReRead VECTOR VECTOR Record is read repeatedly
Seek (STRING) INTEGER Search for a specific sentence
SetBufLength (INTEGER) Sets the buffer area size
SetCodepage
228519
STRING Sets the character set for reading/writing the file.
SetFieldSeparator (STRING) Set field separator
SetRecordSeparator (STRING) Set record separator
SetKey (INTEGER) Setkey field
SetLeftAdjusted (INTEGER, STRING, STRING) Left-justified writing in the buffer area
SetMaxKeyLength (INTEGER) Setkey field length
SetReadOnly Set write protection
SetRecordFormat (VECTOR, INTEGER, INTEGER) Setting a fixed record format
SetRecordSeparator (STRING) Set record separator
SetRightAdjusted (INTEGER, STRING, STRING) Right-aligned writing in the buffer area
SetSkipCRLF (INTEGER)INTEGER Ignore CR/LF at end of block
SetSkipHexNull INTEGERINTEGERTruncate records at hex-zero instead of error message
Update VECTOR. Changing a record
UpdateFromBuffer Modifies a record with the data of the buffer area
UTF8 code Sets the code page to UTF-8
UTF8BOMCode Sets the code page to UTF-8 (with Byte-Order-Mark)
UTF16BigEndianCode Sets the code page to UTF-16 (with big endian)
UTF16LittleEndianCode Sets the code page to UTF-16 (with little-endian)
UTF32LittleEndianCode
235593
Sets the code page to UTF-32 (with little-endian)
Wait
Until Dll version 228508
Synchronisation for parallel access to the same CX_ASCII_File object
Write VECTOR. Writing a sentence
WriteByte (INTEGER) Writing a byte to the file
WriteFromBuffer Writes the buffer area as the next record
ZonedDataFields VECTOR. determine data fields packed in IBM format

* MA = Member Access Function

Data directory (DDI)
Data field Type Reference class I* Brief description
nameOfExchangeFile STRING see FileExchange
fileName STRING File name

* I = Indexable data field

Use in AppsWH
Module Brief description
dtausedt.mod DTAUS file editing module